package jtk.project4.fleet.ibatis.dao;

import java.sql.SQLException;
import java.util.List;

import nl.coderight.jazz.dialog.MessageDialog;
import nl.coderight.jazz.dialog.MessageType;
import jtk.project4.fleet.domain.Local;
import jtk.project4.fleet.domain.Vendor;
import jtk.project4.fleet.domain.VendorType;




public class LocalDao extends IbatisDao{
	
	public List selectLocals() throws SQLException {					
		return getSqlMap().queryForList("SELECT_ALL_LOCAL", null);
	}

	public Local selectLocal(Integer loId) throws SQLException {					
		return (Local) getSqlMap().queryForList("SELECT_LOCAL", loId);
	}
	
	public int deleteLocal(Local local) throws SQLException{
		return (int) getSqlMap().delete("DELETE_LOCAL", local);
	}
	
	public int updateLocal(Local local) throws SQLException{
		return (int) getSqlMap().update("UPDATE_LOCAL", local);
	}
	
	public Local insertLocal(Local local) throws SQLException{
		return (Local) getSqlMap().insert("INSERT_LOCAL", local);
	}	
		
	public static void main (String args[]) throws SQLException{
		Local local;
		local = new Local();
		local.setLoParent(123);
		local.setLocation("Somewhere");
		local.setImage(1);
		local.setPath("This is Path");
		new LocalDao().insertLocal(local);
		
		List locals;
		
		//update
		local.setLoId(8);
		new LocalDao().updateLocal(local);
		
		//delete
		local.setLoId(8);
		new LocalDao().deleteLocal(local);
		
		locals = new LocalDao().selectLocals();
		for (int i=0; i<locals.size(); i++)
		{
			Local getLocals = (Local) locals.get(i);
			
			System.out.println(getLocals.getLocation());
			System.out.println(getLocals.getImage());
			System.out.print(getLocals.getPath());
			System.out.println(getLocals.getImage());
			System.out.println(getLocals.getCreateId());
			System.out.println(getLocals.getLoId());
			System.out.println(getLocals.getLoParent());
			System.out.println(getLocals.getModifyDate());
			System.out.println(getLocals.getModifyId());
			//System.out.println(getLocals.getClass());
			System.out.println("-----------------");
			
		
		}
	}
	
}